package Z.dailyExercise._0225;

public class _剑指Offer05替换空格 {
    /**
     *
     * @param s
     * @return
     */
    public String replaceSpace(String s) {
        if (s.length()==0){
            return s;
        }
        StringBuilder res = new StringBuilder();
        int index =0;
        while (index<s.length() && s.charAt(index) == ' '){
            index++;
            res.append("%20");
        }

        while (index<s.length()){
            if (s.charAt(index)!= ' '){
                res.append(s.charAt(index));
            }else {
                res.append("%20");
            }
            index++;
        }
        return res.toString();

    }
}
